package com.sky.controller.admin;

import com.github.pagehelper.PageHelper;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController
@Api(tags = "套餐相关接口")
@RequestMapping("/admin/setmeal")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @ApiOperation("新增套餐信息")
    @PostMapping()
    public Result save(@RequestBody SetmealDTO setmealDTO){
        log.info("新增套餐信息{}",setmealDTO);
        setmealService.save(setmealDTO);
        return Result.success();
    }

    @ApiOperation("套餐分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("套餐分页查询 {}",setmealPageQueryDTO);
        PageResult pageResult=setmealService.pageQuery(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("删除套餐")
    @DeleteMapping()
    public Result delete(@RequestParam List<Long> ids){
        log.info("删除套餐 {}",ids);
        setmealService.deleteByIds(ids);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("修改套餐的状态")
    public Result status(@PathVariable Integer status,Long id){
        log.info("修改套餐的状态");
        setmealService.status(status,id);
        return Result.success();
    }

    @ApiOperation("套餐修改时信息回显")
    @GetMapping("/{id}")
    public Result<SetmealVO>getInformation(@PathVariable Long id){
        log.info("套餐修改时信息回显：{}",id);
        SetmealVO setmealVO=setmealService.getInfo(id);
        return Result.success(setmealVO);
    }
}
